home *** CD-ROM | disk | FTP | other *** search
/ ASME's Mechanical Engine…ing Toolkit 1997 December / ASME's Mechanical Engineering Toolkit 1997 December.iso / c_lang / tcwindow.lzh / WINDOW.005 < prev    next >
Encoding:
Text File  |  1987-12-06  |  22.1 KB  |  352 lines

  1. .H:
  2. .H:
  3. .H:                Charles G. Nemer                                                                      CIS 166
  4. .H:                WINDOW FUNCTIONS
  5. .H:
  6. .H:
  7. .N:19
  8. .F:                                                                      Page.$$$
  9.     
  10.  
  11.                /*****************************************************************************/
  12.                /*  Function window() is to create the window all that is needed             */
  13.                /*  is to set up the upper left corner, the bottom right corner,             */
  14.                /*  the border color (background-foreground), you should allready            */
  15.                /*  have used set_color(background|foreground) for the window                */
  16.                /*  itself. If a window can not be created window() will pass                */
  17.                /*  back 0, if the window was created the window number will be              */
  18.                /*  passed back.                                                             */
  19.                /*  If the window is to small it will not be allowed to fave a               */
  20.                /*  border, the window with or without a border must be at least             */
  21.                /*  one character space in size. All window are chained together             */
  22.                /*  by pointers and you can move from one window to another.                 */
  23.                /*  window(0,0,24,79,1,0x70);                                                */
  24.                /*****************************************************************************/
  25.  
  26.                int window(char xb,char yb,char xe,char ye,char bdr,unsigned char bdcolor)
  27.                {
  28.                    /*
  29.                      0;         { No border           }     For a border type pass one of
  30.                      1;         { Single border       }     the 13 different border numbers
  31.                      2;         { Double border       }
  32.                      3;         { Mixed border        }
  33.                      4;         { Mixed2 border       }
  34.                      5;         { Solid border        }
  35.                      6;         { Light hatch border  }
  36.                      7;         { Medium hatch border }
  37.                      8;         { Dense hatch border  }
  38.                      9;         { Mixed3 border       }
  39.                     10;         { Mixed4 border       }
  40.                     11;         { Mixed5 border       }
  41.                     12;         { Mixed6 border       }
  42.                     13;         { Mixed7 border       }
  43.                    */
  44.  
  45.                 int out;
  46.                 unsigned int size;                                       /*size of window*/
  47.                 int far *address;                                        /*address of window on screen*/
  48.                 char far *tempdata,char_address;
  49.                 int t,x,y,c,border;
  50.                 unsigned char border_char[13][8]={
  51.                          {'┌','┐','└','┘','─','─','│','│'},              /* single */
  52.                          {'╔','╗','╚','╝','═','═','║','║'},              /* double */
  53.                          {'╒','╕','╘','╛','═','═','│','│'},              /* mixed  */
  54.                          {'╓','╖','╙','╜','─','─','║','║'},              /* mixed2 */
  55.                          {'█','█','█','█','█','█','▌','▐'},              /* solid  */
  56.                          {'░','░','░','░','░','░','░','░'},              /* lhatch */
  57.                          {'▒','▒','▒','▒','▒','▒','▒','▒'},              /* mhatch */
  58.                          {'▓','▓','▓','▓','▓','▓','▓','▓'},              /* dhatch */
  59.                          {0xdf,0xdf,0xdc,0xdc,0xdf,0xdc,0xdd,0xde},      /* mixed3 */
  60.                          {0xda,0xbf,0xc0,0xd9,0xdf,0xdc,0xdd,0xde},      /* mixed4 */
  61.                          {0xda,0xbf,0xc0,0xd9,0xdb,0xdb,0xdb,0xdb},      /* mixed5 */
  62.                          {0xc9,0xbb,0xc8,0xbc,0xdf,0xdc,0xdd,0xde},      /* mixed6 */
  63.                          {0xc9,0xbb,0xc8,0xbc,0xdb,0xdb,0xdd,0xde}       /* mixed7 */
  64.                          };
  65.                 curoff();
  66.                                                                           /* if(ye>=num_col-1){ye=num_col-1;}               /* check to see if the */
  67.                 if (xb>xe) {t=xb;xb=xe;xe=t;}                             /* window begining is  */
  68.                 if (yb>ye) {t=yb;yb=ye;ye=t;}                             /* not after end       */
  69.                  rowb=xb;
  70.                  colb=yb;
  71.                  rowe=xe;
  72.                  cole=ye;
  73.                  border=bdr;
  74.                  if(rowb+2>rowe){border=0;}
  75.                  if(colb+2>cole){border=0;}
  76.  
  77.                  row=rowb;col=colb;
  78.                  size=(rowe-rowb+1)*(cole-colb+1)*2;                      /* check memory for room */
  79.                  if(farcoreleft() < 1000+size+sizeof(struct window_data))
  80.                    {curon();return(FALSE);}                            /* pass 0 if no room     */
  81.                  else                                                     /* make window*/
  82.                  {/*1*/
  83.                  save_window(border,bdcolor,size);                        /* save old screen and window data */
  84.                  clrscr();                                                /* clear the new window using the color from set_color*/
  85.                  if(border>=1)                                            /* if window has a border*/
  86.                  {/*end of else 1*/
  87.                  --border;
  88.                  for(row=rowb;row<=rowe;++row)                            /* draw border */
  89.                     {/*1*/
  90.                       if(rowb<row&&rowe>row)                              /* draw mid section of window*/
  91.                         {/*1*/
  92.                           for (y=0, col=colb;y<=1;y++,col=cole)           /* to end of line*/
  93.                               {/*2*/
  94.                                if(col==colb)                              /* if first collum */
  95.                                  {/*3*/
  96.                                    c=(int)border_char[border][6];         /* c=left side */
  97.                                   }/*end of if3*/
  98.                                  else                                     /* display right side */
  99.                                    {/*2*/
  100.                                       c=(int)border_char[border][7];      /* c=right side */
  101.                                     }/*end of else2*/
  102.                                   address = screenbase + ((row * num_col) + col);
  103.                                   c=((bdcolor<<8)|c);                      /* add color to c and write to screen*/
  104.                                   if(fast==TRUE) {foutput(address,c,1);}   /* if no snow*/
  105.                                   else output(address,c,1);                /* if snow*/
  106.                                 }/*end of for2*/
  107.                              continue;                                     /* do next row*/
  108.                            }/*end of if2*/
  109.  
  110.                            if(row==rowb)                                   /* draw top line*/
  111.                              {/*4*/
  112.                               for (col=colb;col<=cole;++col)               /* to end of line*/
  113.                                 {/*3*/
  114.                                  if(col==colb)                             /* if left corner*/
  115.                                    { /*5*/
  116.                                      c=(int)border_char[border][0];        /* c=left corner*/
  117.                                     }/*end of if5*/
  118.                                   else                                     /* mid section*/
  119.                                      {/*3*/
  120.                                        c=(int)border_char[border][4];      /* c=mid section*/
  121.                                       }/*end of else3*/
  122.                                   if(col==cole)                            /* if right corner*/
  123.                                     {/*6*/
  124.                                       c=(int)border_char[border][1];       /* c=right corner*/
  125.                                      }/*end of if6*/
  126.                                    address = screenbase + ((row * num_col) + col);  /* address where to put character*/
  127.                                    c=((bdcolor<<8)|c);                     /* add color to c and write to screen*/
  128.                                    if(fast==TRUE) {foutput(address,c,1);}  /* if no snow use this*/
  129.                                    else output(address,c,1);               /* moniter has snow */
  130.                                  }/*end of for3*/
  131.                                  continue;                                 /* draw next row*/
  132.                              }/*end of if4*/
  133.  
  134.                             if(row==rowe)                                  /* draw bottom line*/
  135.                              {/*7*/
  136.                               for (col=colb;col<=cole;++col)               /* to end of line*/
  137.                                  {/*4*/
  138.                                   if(col==colb)                            /* if left corner*/
  139.                                     {/*8*/
  140.                                      c=(int)border_char[border][2];        /* c= bottom left corner*/
  141.                                      }/*end of if8*/
  142.                                    else                                    /* if mid section*/
  143.                                      {/*4*/
  144.                                       c=(int)border_char[border][5];       /* c=mid section*/
  145.                                       }/*end of else4*/
  146.                                    if(col==cole)                           /* if right side*/
  147.                                      {/*9*/
  148.                                       c=(int)border_char[border][3];       /* c=bottom right corner*/
  149.                                      }/*end of if9*/
  150.                                      address = screenbase + ((row * num_col) + col);  /* address where to put c*/
  151.                                      c=((bdcolor<<8)|c);                   /* add color to c and write to screen*/
  152.                                      if(fast==TRUE) {foutput(address,c,1);}/* no snow*/
  153.                                      else output(address,c,1);             /* snow*/
  154.                                  }/*end of for4*/
  155.                              }/*end of if7*/
  156.                           }/*end of for1*/
  157.                        ++border;                                           /* restore border*/
  158.                     }/*end of if1*/
  159.  
  160.                  if(border>=1)                                             /* if window has a*/
  161.                  { /*10*/                                                  /* border shrink*/
  162.                    ++rowb;                                                 /* window to fit*/
  163.                    ++colb;
  164.                    --rowe;
  165.                    --cole;
  166.                  }/*end of if10*/                                          /* put cursor in */
  167.                  row=rowb;col=colb;                                        /* right hand top */
  168.                  set_cur(rowb,colb);                                       /* corner*/
  169.                  present->wcurr = row;
  170.                  present->wcurc = col;
  171.                  }/*end of else1*/
  172.                 curon();
  173.                 return(present->wnumber);
  174.                }/*end of window()*/
  175.  
  176.  
  177.  
  178.  
  179.                /*****************************************************************************/
  180.                /* delete_window() will delete any window that you are not presently in. The */
  181.                /* only time you can delete a window that you are is when you are at the end */
  182.                /* of the chain and pass 0 to delete_window(0); . This will delete the end   */
  183.                /* window (link) and put you in the new end window (link).                   */
  184.                /* delete_window is not smart yet so, if a window is on top of the window you*/
  185.                /* delete the old data will be placed over the top window, so you must keep  */
  186.                /* track of the windows your self.                                           */
  187.                /* if window is not found 0 will be pass back and if window was deleted a -1 */
  188.                /* will be returned.                                                         */
  189.                /* You MUST use option 0 to delete the last window.                          */
  190.                /* delete_window(5);                                                         */
  191.                /*****************************************************************************/
  192.  
  193.                int delete_window(unsigned short wnum)
  194.                {
  195.                 int far *windstore;                                       /* pionters to save area*/
  196.                 int far *temp;
  197.                 unsigned int size;
  198.                 int x,y;
  199.                 unsigned short srowb,scolb,srowe,scole,
  200.                          snum_col,store_size;
  201.                 struct window_data far *windata;                          /* pionters to the window struct*/
  202.                 curoff();
  203.                 if(number_of_windows>0)                                   /* if 0 no windows*/
  204.                  {/*1*/
  205.                  present->wcurr=row;                                      /* save curser of present window*/
  206.                  present->wcurc=col;
  207.                  if(wnum>0)                                               /* if not 0 find window to*/
  208.                  {/*2*/                                                   /* delete*/
  209.                   windata=present;                                        /* if not same as present*/
  210.                   if(windata->wnumber!=wnum)                              /* find*/
  211.                   {/*3*/
  212.                     if(windata->wnumber>wnum)                             /* go back*/
  213.                        {/*4*/
  214.                        while(windata->last!=NULL && windata->wnumber!=wnum)  /* and find window or end of chain*/
  215.                             {windata=windata->last;}
  216.                        if(windata->wnumber!=wnum)return(FALSE);              /* was window found or NULL if NULL return 0*/
  217.                        }/*end of if4*/
  218.                     else                                                  /* check to end*/
  219.                        {/*1*/                                             /*go fowards*/
  220.                        while(windata->next!=NULL && windata->wnumber!=wnum)
  221.                             {windata=windata->next;}
  222.                        if(windata->wnumber!=wnum)return(FALSE);           /* if not found return -1*/
  223.                        }/*end of else1*/
  224.                    }/*end of if3*/
  225.                    else {curon();return(FALSE);}                       /* if same window, can not delete same window*/
  226.                  }/*end of if2*/                                          /* that you are on with this option*/
  227.                  else if(wnum==0)windata=last;                            /* used option 0 delete last window*/
  228.                  if(wnum>=0)                                              /* delete window if a positive number*/
  229.                   {/*5*/
  230.                     if(last==windata)last=windata->last;                  /*set last window if new*/
  231.                     windstore=windata->addressave;                        /*get address of saved screen*/
  232.                     srowb=windata->wrowb;scolb=windata->wcolb;            /*restore window data*/
  233.                     srowe=windata->wrowe;scole=windata->wcole;
  234.                     snum_col=windata->wnum_col;
  235.                     store_size=((scole-scolb)+1);
  236.                     for(row=srowb;row<=srowe;row++)                       /* restore screen */
  237.                       { /*1*/
  238.                         temp=screenbase+((row * snum_col) + scolb);       /* address of screen pos*/
  239.                         if(fast==TRUE) {fscreen(temp,windstore,store_size);}/* no snow*/
  240.                         else screen_in(temp,windstore,store_size);          /* snow*/
  241.                         windstore+=store_size;                            /* next line*/
  242.                       }/*end of for1*/
  243.  
  244.                    }/*end of if5*/
  245.                                                                           /* if last window was deleted*/
  246.                   if(wnum==0 && last!=NULL)                               /* restore if option 0*/
  247.                     {/*6*/                                                /* and window to restore*/
  248.                        present=last   ;                                   /* present window is last window*/
  249.                        wcolor=present->wcolor;                            /* get setup of*/
  250.                        rowb=present->wrowb;colb=present->wcolb;           /* new present */
  251.                        rowe=present->wrowe;cole=present->wcole;           /* window*/
  252.                        page=present->wpage;num_col=present->wnum_col;
  253.                        screenbase=present->screenbase;
  254.                        row=present->wcurr; col=present->wcurc;
  255.                        set_cur(row,col);
  256.                        if(present->bd>=1)                                 /* if border shrink*/
  257.                          {/*7*/                                           /* window*/
  258.                           ++rowb;
  259.                           ++colb;
  260.                           --rowe;
  261.                           --cole;
  262.                          }/*end of if7*/
  263.                     }/*end of if6*/
  264.  
  265.  
  266.  
  267.                   if(windata->next!=NULL && windata->last!=NULL)          /* relink chain*/
  268.                     {/*8*/
  269.                       windata->last->next=windata->next;
  270.                       windata->next->last=windata->last;
  271.                     }/*end of if8*/
  272.                   else
  273.                     {/*3*/
  274.                       if(windata->last==NULL && windata->next!=NULL)      /* or NULL end*/
  275.                         {windata->next->last=NULL;}
  276.                       if(windata->next==NULL && windata->last!=NULL)
  277.                         {windata->last->next=NULL;}
  278.                      }/*end of else3*/
  279.  
  280.                   farfree(windata);                                       /* free momory*/
  281.                   number_of_windows--;                                    /* dec number of windows*/
  282.                   if(number_of_windows==0)                                /* if last windo restore*/
  283.                     {/*9*/                                                /* screen data*/
  284.                       num_col=fnum_col;
  285.                       page=fpage;
  286.                       row=frow;col=fcol;
  287.                       rowb=frowb;colb=fcolb;
  288.                       rowe=frowe;cole=fcole;
  289.                       screenbase=fscreenbase;
  290.                       wcolor=fcolor;
  291.                       set_cur(row,col);
  292.                      }/*end of if9*/
  293.                    
  294.                  }/*end of if1*/
  295.                  curon();
  296.                  return(TRUE);
  297.                }/*end of main*/
  298.  
  299.  
  300.  
  301.                /*****************************************************************************/
  302.                /* To change to another window all you have to do is pass the window number  */
  303.                /* assigned to it when make. If you can move to the window a -1 will be      */
  304.                /* passed back else a 0 if not.                                              */
  305.                /* change_window(5);                                                         */
  306.                /*****************************************************************************/
  307.  
  308.                change_window(unsigned short wnum)
  309.                {
  310.                unsigned short num;
  311.                struct window_data far *windo,far *windata;
  312.                windata=present;
  313.                reg.h.ah = 3;                                              /* get cursor position */
  314.                reg.h.bh = page;                                           /* page */
  315.                int86(0x10,®,®);
  316.                windata->wcurr = reg.h.dh;                                 /* update this window struct*/
  317.                windata->wcurc = reg.h.dl;                                 /* befor moving*/
  318.                if(windata->wnumber!=wnum)                                 /* find new window*/
  319.                  {
  320.                    if(windata->wnumber>wnum)                              /* is window you are at after*/
  321.                       {                                                   /* window you need*/
  322.                       while(windata->last!=NULL&&windata->wnumber!=wnum)
  323.                            {windata=windata->last;}                       /* move back*/
  324.                       if(windata->wnumber!=wnum)return(FALSE);            /* if not found return false*/
  325.                       }
  326.                    else
  327.                       {                                                   /* window is befor window you need*/
  328.                       while(windata->next!=NULL&&windata->wnumber!=wnum)
  329.                            {windata=windata->next;}                       /* get next window*/
  330.                       if(windata->wnumber!=wnum)return(FALSE);            /* not found*/
  331.                       }
  332.                    present=windata;                                       /* found window*/
  333.                    row=windata->wcurr; col=windata->wcurc;                /* get cursor data*/
  334.                    set_cur(row,col);                                      /* set cursor*/
  335.                    wcolor=windata->wcolor;
  336.                    rowb=windata->wrowb;colb=windata->wcolb;               /* restore window data*/
  337.                    rowe=windata->wrowe;cole=windata->wcole;
  338.                    page=windata->wpage;num_col=windata->wnum_col;
  339.                    screenbase=windata->screenbase;
  340.                    if(windata->bd>=1)                                     /* if a border make window fit*/
  341.                      {
  342.                       ++rowb;
  343.                       ++colb;
  344.                       --rowe;
  345.                       --cole;
  346.                       }
  347.                  }
  348.                    return(TRUE);
  349.                }
  350.  
  351.                
  352.